#ifndef WEBSOCKETCLIENT_H
#define WEBSOCKETCLIENT_H

#include <memory>

#include <QObject>
#include <QSslError>

class QWebSocket;

namespace ServerMsgViewer {

using namespace std;

class WebSocketClient : public QObject {

    Q_OBJECT

    typedef enum {
        OK,
        ERR_BAD_URL,
        ERR_CANT_BUILD_WS,
        ERR_WS_NOT_EXIST,
        ERR_NO_ACTIVE_CONNECTION
    } WebSocketClientStatus;

public:
    WebSocketClient();
    virtual ~WebSocketClient();

public:
    WebSocketClientStatus openUrl(QString url);
    WebSocketClientStatus close();
    WebSocketClientStatus sendMsg(const QString& msg);
    WebSocketClientStatus ping();

signals:
    void onMsgRecved(QString s);
    void onConnected();
    void onDisConnected();

private slots:
    void onSslErrors(const QList<QSslError>& errors);

private:
    unique_ptr<QWebSocket> _client;
};
}

#endif // WEBSOCKETCLIENT_H
